﻿using System.Data;
using System.Windows;
using WpfApp1.tools;

namespace WpfApp1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // 获取数据库实例
            DBConnection conn = new DBConnection();
            string sqlStr = "Select * from users";

            // 调用查询方法
            DataTable dataset = conn.Select(sqlStr);
            // 得到返回结果，并赋值到表格上
            DataGrid1.ItemsSource = dataset.DefaultView;
            if (dataset == null)
            {
                MessageBox.Show("没有数据");
            }
            else
            {
                MessageBox.Show("有数据");
            }

            System.Diagnostics.Debug.WriteLine("查询到结果的行数:" + dataset.Rows.Count);
            for (var i = 0; i < dataset.Rows.Count; i++)
            {
                var row = dataset.Rows[i];
                var str = "";
                for (var j = 0; j < row.ItemArray.Length; j++)
                {
                    str += row[j] + "_";
                }
                System.Diagnostics.Debug.WriteLine("row：" + i + " " + str);
            }
            
            // https://blog.csdn.net/qq_37171353/article/details/78198415
            // DataGrid1.ItemsSource = dataset.DefaultView;
            // 原文链接：https://blog.csdn.net/qq_43026206/article/details/86706431
        }
    }
    // 原文链接：https://blog.csdn.net/qq_43026206/article/details/86706431
}
